//
//  UserionfsViewController.m
//  penzer
//
//  Created by caiyc on 2018/10/12.
//  Copyright © 2018年 caiyc. All rights reserved.
//

#import "UserionfsViewController.h"
#import "OrderViewController.h"
#import "FouceHostViewController.h"
#import "CollectViewController.h"
#import "SetViewController.h"
#import "EditInfoViewController.h"
#import "GSetViewController.h"
#import "ContactsViewController.h"
#import "RechargeViewController.h"
#import "RenwuViewController.h"
#import "CProGressView.h"
#import "LevelViewController.h"
#import "NotiViewController.h"
#import "GuestCouponHomeViewController.h"
@interface UserionfsViewController ()

@end

@implementation UserionfsViewController
-(void)loadData{
//    http://dev.sharepanzer.com/api/bzapi.php?i=10&c=entry&ctrl=live&ac=member&op=member&m=bz_activities&token=d6c58d58c38f023f92327383594aa192&ta=get_member
    NSDictionary *params = @{@"ctrl":@"live",@"ac":@"member",@"op":@"member",@"ta":@"get_member"};
    [self weqPostHandle:params success:^(id response) {
        if(response){
            NSDictionary *dic = [NSDictionary changeType:response[@"data"]];
            [XTool SaveDefaultInfo:dic Key:USER_INFO];
            self.nect_Lvecel.text = [NSString stringWithFormat:@"还差%@经验值升级",response[@"data"][@"next_level"]];
        }
    } failure:^(NSError *error) {
        
    }];
}
-(void)viewWillAppear:(BOOL)animated{
    [self loadData];
    if([XTool GetDefaultInfo:USER_INFO]){
        NSDictionary *userDic = [XTool GetDefaultInfo:USER_INFO];
       // NSLog(@".......%@",userDic);
        NSURL *url = [NSURL URLWithString:userDic[@"avatar"]];
        NSInteger level  = [userDic[@"groupid"]integerValue]+1;
        NSString *str = [NSString stringWithFormat:@"level%ld",level];
        self.level_Img.image = [UIImage imageNamed:str];
        [self.icon sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"Bitmap"]];
        self.nickName.text = [userDic[@"nickname"]isEqualToString:@""]?@"暂无":userDic[@"nickname"];
       
        NSInteger totals = [userDic[@"exp"]integerValue]+[userDic[@"next_level"]integerValue];
       CGFloat percent =  [userDic[@"exp"]floatValue]/totals;
        CProGressView *progress = (CProGressView *)[self.view viewWithTag:11001];
        progress.progressValue = [NSString stringWithFormat:@"%.2f",percent];
    }
}
- (IBAction)contact:(UIButton *)sender {
    NSInteger index = sender.tag;
    ContactsViewController *vc = [[ContactsViewController alloc]init];
    if(index==0){
        vc.title = @"通讯录";
         [self pushSecondVC:vc];
    }else if (index==1)
    {
//        vc.title = @"卡券包";
//        [self pushSecondVC:vc];
        
        GuestCouponHomeViewController *coupon = [[GuestCouponHomeViewController alloc] initWithViewType:CouponViewTypeHome];
        [self pushSecondVC:coupon];
        
    }else{
        NotiViewController *vc = [[NotiViewController alloc]init];
        [self pushSecondVC:vc];
    }
}



- (IBAction)func_Action:(UIButton *)sender {
    NSInteger index = sender.tag;
    if(index==2){
        FouceHostViewController *vc = [[FouceHostViewController alloc]init];
        [self pushSecondVC:vc];
    }else if (index==3){
        CollectViewController *vc = [[CollectViewController alloc]init];
        [self pushSecondVC:vc];
    }else if (index==4){
        GSetViewController *vc = [[GSetViewController alloc]init];
        [self pushSecondVC:vc];
//        SetViewController *vc = [[SetViewController alloc]init];
//        [self pushSecondVC:vc];
    }else if (index==0){
        RenwuViewController *vc = [[RenwuViewController alloc]init];
        [self pushSecondVC:vc];
        return;
    }
    else{
        RechargeViewController *vc = [[RechargeViewController alloc]init];
        [self pushSecondVC:vc];
        return;
//        ContactsViewController *vc = [[ContactsViewController alloc]init];
//        vc.title= @"增值机会";
//        [self pushSecondVC:vc];
    }
}
- (IBAction)checkOrder:(UIButton *)sender {
    
    GuestOrderType type = GuestOrderType_ALL;
    switch (sender.tag) {
        case 0:type = GuestOrderType_ALL;
            break;
        case 1:type = GuestOrderType_YFH;
            break;
        case 2:type = GuestOrderType_DPJ;
            break;
        case 3:
       
            type = GuestOrderType_SQTH;
            break;
    }
    if(type == GuestOrderType_SQTH){
        
            ContactsViewController *vc = [[ContactsViewController alloc]init];
            
            vc.title = @"售后";
            [self pushSecondVC:vc];
        
    }else{
        OrderViewController *bvc = [[OrderViewController alloc]initWithGuestOrderType:type];
        [self pushSecondVC:bvc];
    }
    
}


//点击查看个人信息
- (IBAction)checkUsreInfo:(UIButton *)sender {
    EditInfoViewController *vc = [[EditInfoViewController alloc]init];
    [self pushSecondVC:vc];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    CProGressView *progress = [[CProGressView alloc]initWithFrame:CGRectMake(0, 0, self.progressView.frame.size.width-30, 7)];
    progress.tag = 11001;
    [self.progressView addSubview:progress];
//    progress.progressValue = @"0.7";
   self.botom_ScoView.contentSize = CGSizeMake(0, 780);
  
    self.botom_ScoView.showsVerticalScrollIndicator = 0;
    self.icon.layer.cornerRadius = 45;
    self.icon.layer.masksToBounds = 1;
    self.flashScro.contentSize = CGSizeMake(screen_width*3, 0);
    self.flashScro.pagingEnabled = 1;
    for(int i =0;i<3;i++){
        UIImageView *image = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"userflash.png"]];
        image.frame = CGRectMake(screen_width*i, 0, screen_width, self.flashScro.frame.size.height);
        
        [self.flashScro addSubview:image];
    }
    [self setNavigation:1 andTitle:@"我的" andNaviColor:nil andTitleColor:nil andRightimg:@"" andsel:@selector(set)];
    [self loadData];
    // Do any additional setup after loading the view from its nib.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (IBAction)checkLevel:(UIButton *)sender {
    LevelViewController *vc = [[LevelViewController alloc]init];
    [self pushSecondVC:vc];
}
@end
